package com.hefeng.unit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hefeng.common.core.web.domain.AjaxResult;
import com.hefeng.unit.controller.entity.ParamEntity;
import com.hefeng.unit.domain.GyDevice;
import com.hefeng.unit.domain.GyDeviceSon;
import com.hefeng.unit.service.SonService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/unit/son")
public class SonController {
    /**
     *
     */
   @Autowired
   private SonService sonService;
    @PostMapping(value = "/list", produces = "application/json;charset=UTF-8")
    @ApiOperation("根据登录用户获取该用户子设备列表")
    public AjaxResult list(@RequestBody GyDeviceSon gyDeviceSon) {

        Map<String,Object> data=new HashMap<String,Object>();
        List<GyDeviceSon> gasList=sonService.list(gyDeviceSon.getDeviceCode());
        data.put("gasList",gasList);
        return AjaxResult.success(gasList);

    }

    /**
     *
     * @param gyDeviceSon
     * @return
     */
    @PostMapping(value = "/select", produces = "application/json;charset=UTF-8")
    @ApiOperation("获取子设备详情")
    public AjaxResult slelct( @RequestBody GyDeviceSon  gyDeviceSon) {

//        Map<String,Object> data=new HashMap<String,Object>();
//        Page<GyDeviceSon> gasList=sonService.select(id);
//        data.put("gasList",gasList);
        return AjaxResult.success(sonService.select(gyDeviceSon));
    }

    /**
     *
     * @param gyDeviceSon
     * @return
     */
    @PostMapping(value = "/update", produces = "application/json;charset=UTF-8")
    @ApiOperation("删除")
    public AjaxResult update( @RequestBody GyDeviceSon  gyDeviceSon){
        return AjaxResult.success(sonService.update(gyDeviceSon));
    }


    @PostMapping(value = "/ziUpdate", produces = "application/json;charset=UTF-8")
    @ApiOperation("修改")
    public AjaxResult updateS( @RequestBody GyDeviceSon  gyDeviceSon){
        Map<String, Object> data=sonService.updateZ(gyDeviceSon);
        if(!data.get("make").equals(true)){
            return AjaxResult.error(501,data.get("msg").toString());
        }
        return AjaxResult.success("修改成功！",data);
    }



}
